import http from "./index";

//搜索建议
export const searchSuggest = async (keywords: string) => {
  let { result }: any = await http.get("/search/suggest", { keywords });
  return result;
};

//默认搜索建议
export const searchHotDetail = async () => {
  let { data }: any = await http.get("search/hot/detail");
  return data;
};

//获取banner
export const getBanner = async () => {
  let { banners }: any = await http.get("/banner");
  return banners;
};

//登录，此接口暂时无法使用
export const getLogin = async (data: { phone: string; password: string }) => {
  let res = await http.get("/login/cellphone", data);
  return res;
};

//获取短信验证码
export const getQrKey = async () => {
  return await http.get("/login/qr/key");
};

//二维码生成接口
export const getQrLogin = async (data: { key: string; qrimg: string }) => {
  let res = await http.get("/login/qr/create", data);
  return res;
};

//二维码生成接口
export const getCheck = async (data: { key: string }) => {
  let res = await http.get("/login/qr/check", data);
  return res;
};

//推荐歌单
export const getRecommendedSongList = async () => {
  let { result }: any = await http.get("/personalized");
  return result;
};

//获取歌曲详情
export const getSongListDetail = async (id: number | string) => {
  let { songs }: any = await http.get("/song/detail", { ids: id });
  return songs[0];
};

//获取歌单详情
export const getPlaylistDetail = async (id: number | string) => {
  let res: any = await http.get("/playlist/detail", { id });
  return res;
};

//获取歌单列表
export const getSongs = async (id: number | string) => {
  let { songs }: any = await http.get("/playlist/track/all", { id });
  return songs;
};

//获取音乐url
export const getSongUrl = async (
  id: number | string,
  level: string = "higher"
) => {
  let { data }: any = await http.get("/song/url/v1", { id, level });
  return data;
};

//获取搜索结果
export const getSearchDetail = async (
  keywords: string,
  type: number = 1,
  offset: number
) => {
  let { result }: any = await http.get("/cloudsearch", {
    keywords,
    type,
    offset,
  });
  return result;
};

//获取歌曲相关MV
export const getVideo = async (id: string) => {
  let res: any = await http.get("/mv/url", { id });
  return res;
};
